<template>
  <system-index @to-main-page="toMainPage">
    <one-auction-detail ref="oneAuction" :has-back="hasBack" @to-page="toPage"></one-auction-detail>
  </system-index>
</template>

<script>
  import SystemIndex from 'views/systemIndex';
  import OneAuctionDetail from 'views/oneAuctionDetail';

  import mpMixins from '../mpMixins';

  export default {
    mixins: [mpMixins],

    data() {
      let pages = getCurrentPages();
      return {
        hasBack: pages.length > 1,
        paySuccess: false
      };
    },

    created() {
      window.toPaymentSuccess = () => {
        this.paySuccess = true;
        return window.Promise.resolve(true);
      };

      window.addEventListener('wxshow', () => {
        let paySuccess = this.paySuccess;
        if (paySuccess) {
          this.paySuccess = false;
          this.$refs['oneAuction'].resetAuctionData();
        }
      });

      window.onShareAppMessage = function () {
        let href = window.location.href;
        let origin = window.location.origin;
        let url = href.substring(origin.length);
        return {
          path: url
        }
      };
    },

    components: {
      SystemIndex,
      OneAuctionDetail
    }
  };

</script>
